package myJs.myPkg

import myJs.Implicits.JDJAn
import myJs.myPkg.jquery.JQuery
import myJs.myPkg.jsext._
import slinky.readwrite.ObjectOrWritten

import scala.scalajs.js
import scala.language.implicitConversions
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.annotation.JSImport.Namespace
import scala.scalajs.js.|


/**
  * Created by yz on 2019/3/14
  */

@js.native
trait Select2JQuery extends js.Object {

  def select2(options: ObjectOrWritten[Select2Options]): JQuery = scalajs.js.native

  def select2(): JQuery = scalajs.js.native

  def select2(method:String): JQuery = scalajs.js.native

  def select2(method:String,data:js.Any,b:Boolean): JQuery = scalajs.js.native

  def select2(method:String,data:js.Any): JQuery = scalajs.js.native

}

case class Params(term:String,page:js.UndefOr[Int],pageSize:js.UndefOr[Int])

case class AjaxOptions(
  url: js.UndefOr[String] = js.undefined,
  dataType: js.UndefOr[String] = js.undefined,
  data: js.UndefOr[Params=>js.Dictionary[js.Any]] = js.undefined,
  processResults: js.UndefOr[JDJAn=>js.Dictionary[js.Any]] = js.undefined,
  `type`: js.UndefOr[String] = js.undefined,
  delay: js.UndefOr[Int] = js.undefined,
  cache: js.UndefOr[Boolean] = js.undefined,
)

case class Select2Options(
  placeholder: js.UndefOr[String] = js.undefined,
  allowClear: js.UndefOr[Boolean] = js.undefined,
  data: js.UndefOr[List[String] | js.Array[js.Dictionary[String]]] = js.undefined,
  dropdownParent: js.UndefOr[JQuery] = js.undefined,
  multiple: js.UndefOr[Boolean] = js.undefined,
  minimumResultsForSearch: js.UndefOr[Int] = js.undefined,
  ajax: js.UndefOr[AjaxOptions] = js.undefined,
  minimumInputLength: js.UndefOr[Int] = js.undefined,
  disabled: js.UndefOr[Boolean] = js.undefined,
)


trait Select2JQueryImplicits {

  implicit def implicitSelect2JQuery(jq: JQuery) = {
    jq.asInstanceOf[Select2JQuery]
  }
}


